<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../css/elementUI.css">
    <script src="../js/vue.js"></script>
    <script src="../js/axios.js"></script>
    <script src="../js/elementUI.js"></script>
    <script src="../js/echarts.min.js"></script>

</head>
<body>

<div id="app">
    <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
    <div id="main" style="width: 100%;height:400px;"></div>

    <el-table
            ref="multipleTable"
            :data="tableData"
            tooltip-effect="dark"
            style="width: 100%">
        <el-table-column
                prop="pname"
                label="产地名称">
            <template slot-scope="scope">
                <span>{{scope.row.name}}</span>
            </template>
        </el-table-column>

        <el-table-column
                prop="value"
                label="水果数量">
            <template slot-scope="scope">
                <span>{{scope.row.value}}</span>
            </template>
        </el-table-column>

    </el-table>
</div>

</body>
<script>
    new Vue({
        el: "#app",
        data: {
            tableData: [],
        },
        methods: {
            initData() {
                axios.post("/count/tongji.do").then(res => {
                   this.tableData=res.data;
                    this.initEchartsInfo();
                })
            },
            initEchartsInfo(){
                // 基于准备好的dom，初始化echarts实例
                var myChart = echarts.init(document.getElementById('main'));
                let nameArray=[]; //名称
                let numArray=[]; //数量

                for (let i = 0; i < this.tableData.length; i++) {
                    let obj =this.tableData[i]
                    nameArray.push({name:obj.name,value:obj.money})
                    numArray.push({name:obj.name,value:obj.value})
                }
                // 指定图表的配置项和数据
                var option = {
                    title: {
                        text: '分类数据统计',
                        subtext: '',
                        left: 'center'
                    },
                    tooltip: {
                        trigger: 'item'
                    },
                    legend: {
                        orient: 'horizontal',
                        bottom:"5%",
                        left: 'circle',
                    },
                    series: [
                        {
                            name: '订单数量',
                            type: 'pie',
                            radius: '50%',
                            center:['30%','50%'],
                            data:numArray,
                            emphasis: {
                                itemStyle: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        },
                        {
                            name: '商品金额',
                            type: 'pie',
                            radius: '50%',
                            center:['70%','50%'],
                            data:nameArray,
                            emphasis: {
                                itemStyle: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }

                    ]
                };

                // 使用刚指定的配置项和数据显示图表。
                myChart.setOption(option);

            },
        },
        created() {
            this.initData();
        }
    })
</script>
</html>